﻿@model ContentHistoryModel

@{
	ViewBag.Title = "Content Edit History";
}

@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "contentIndex" })) {
	@Html.AntiForgeryToken()

	var grid = CarrotWeb.CarrotWebGrid<EditHistory>(Model.Page);

	grid.TableAttributes = new { @class = "datatable" };
	grid.THeadAttributes = new { @class = "tablehead" };
	grid.EmptyDataTemplate = @<text><p> <b>No records found.</b> </p></text>;
	grid.HtmlFormId = "contentIndex";
	grid.PageSizeExternal = true;
	grid.ConfigName(Html.NameFor(x => x.Page));

	grid.SetupFooter("ul", new { @class = "tablepager ui-widget ui-helper-clearfix ui-widget-content ui-corner-all" }, "li", new { @class = "ui-state-default ui-state-active ui-corner-all" }, new { @class = "ui-state-default ui-corner-all" });

	List<CarrotImageColumnData> typeImgs = new List<CarrotImageColumnData>();
	typeImgs.Add(new CarrotImageColumnData(ContentPageType.PageType.ContentEntry, "~/Assets/Admin/Images/page_world.png", "Page"));
	typeImgs.Add(new CarrotImageColumnData(ContentPageType.PageType.BlogEntry, "~/Assets/Admin/Images/blogger.png", "Post"));

	grid
	.AddColumn(new CarrotGridTemplateColumn<EditHistory> {
		HasHeadingText = false,
		FormatTemplate = @<a target="_blank" href="@item.FileName">
			<img src="~/Assets/Admin/Images/html.png" alt="Visit Page" title="Visit Page" />
		</a>
	})
	.AddColumn(new CarrotGridTemplateColumn<EditHistory> {
		HasHeadingText = false,
		FormatTemplate = @<text>
			<a href="javascript:void(0)" onclick="@String.Format("ShowWindowNoRefresh('{0}/{1}')", SiteFilename.PageHistoryURL, item.Root_ContentID)">
				<img src="~/Assets/Admin/Images/hourglass.png" alt="View Page History" title="View Page History" />
			</a>
		</text>
	})
	.AddColumn(x => x.NavMenuText, new CarrotGridColumn { Sortable = true })

	.AddColumn(x => x.ContentTypeValue, new CarrotGridImageColumn {
		Sortable = true,
		ImagePairs = typeImgs
	})

	.AddColumn(x => x.EditUserName, new CarrotGridColumn { Sortable = true })
	.AddColumn(x => x.EditDate, new CarrotGridColumn { Sortable = true, CellFormatString = "{0:M/d/yyyy} {0:h:mm tt}" })

	.AddColumn(x => x.CreateUserName, new CarrotGridColumn { Sortable = true })
	.AddColumn(x => x.CreateDate, new CarrotGridColumn { Sortable = true, CellFormatString = "{0:M/d/yyyy} {0:h:mm tt}" })

	.AddColumn(x => x.GoLiveDate, new CarrotGridColumn { Sortable = true, CellFormatString = "{0:M/d/yyyy}" })
	.AddColumn(x => x.RetireDate, new CarrotGridColumn { Sortable = true, CellFormatString = "{0:M/d/yyyy}" })

	.AddColumn(x => x.IsLatestVersion, new CarrotGridBooleanImageColumn {
		AlternateTextTrue = "Latest",
		AlternateTextFalse = "Not Latest",
		Sortable = true
	})
	.AddColumn(x => x.PageActive, new CarrotGridBooleanImageColumn {
		AlternateTextTrue = "Active",
		AlternateTextFalse = "Inactive",
		Sortable = true
	});

	<p>
		@Html.TextBoxFor(m => m.SearchDate, "{0:MM/dd/yyyy}", new { @class = "dateRegion form-control-sm", maxlength = "12", size = "16" })
	</p>
	<p>
		@Html.CheckBoxFor(m => m.GetLatestOnly)
		@Html.LabelFor(m => m.GetLatestOnly)
	</p>
	<p>
		@Html.LabelFor(m => m.SelectedUserID)
		@Html.DropDownListFor(m => m.SelectedUserID, new SelectList(Model.UserList, "Key", "Value"), "[Select User]")
	</p>
	<p>
		<label for="@Html.IdFor(m => m.Page.PageSize)">Change Page Size</label>
		@Html.DropDownListFor(m => m.Page.PageSize, new SelectList(Model.PageSizes.Select(x => new { Value = x, Text = x }), "Value", "Text"))
	</p>
	<p>
		<input id="btnApply" type="submit" value="Apply" name="btnApply">
	</p>
	<p>
		@String.Format("{0} total records", grid.DataPage.TotalRecords)
	</p>

	<div class="tablezone">
		@grid.Write()
	</div>
}